#undef UNICODE
#undef _UNICODE
#pragma once
#ifndef WINVER				// Allow use of features specific to Windows XP or later.
#define WINVER 0x0501		// Change this to the appropriate value to target other versions of Windows.
#endif

#ifndef _WIN32_WINNT		// Allow use of features specific to Windows XP or later.                   
#define _WIN32_WINNT 0x0501	// Change this to the appropriate value to target other versions of Windows.
#endif						

#ifndef _WIN32_WINDOWS		// Allow use of features specific to Windows 98 or later.
#define _WIN32_WINDOWS 0x0410 // Change this to the appropriate value to target Windows Me or later.
#endif

#ifndef _WIN32_IE			// Allow use of features specific to IE 6.0 or later.
#define _WIN32_IE 0x0600	// Change this to the appropriate value to target other versions of IE.
#endif

#define WIN32_LEAN_AND_MEAN		// Exclude rarely-used stuff from Windows headers
#include <stdio.h> 
#include <stdlib.h>
#include <windows.h>
#include <shellapi.h>
#include <tchar.h>
#include <wmistr.h>
#include <initguid.h> // guiddef
#include <evntrace.h>
#include "strsafe.h"

#include "constants.h"
#include "model.h"

#include <jni.h>

// DECL

void Register(); 
void Unregister(); 
ULONG control( IN WMIDPREQUESTCODE requestCode, IN PVOID Context, IN OUT ULONG *InOutbufferSize, IN OUT PVOID buffer);
void SessionInitialize(PEVENT_TRACE_PROPERTIES& loggerdata);
void SessionStart(PEVENT_TRACE_PROPERTIES loggerdata);
void SessionEnable();
void SessionDisable(); 
void ControlStop(PEVENT_TRACE_PROPERTIES loggerdata);
ULONG FireBasicFormat(const char* message);
// reader
ULONG WINAPI BufferCallback(PEVENT_TRACE_LOGFILE pLog);
void WINAPI DumpEvent(PEVENT_TRACE pEvent);
ULONG ReadWholeTrace(const char* loggerName, const char* etlPath, const char* txtPath);

// ENTRIES!
extern "C"
{
ULONG __stdcall InitializeEtw(const char* loggerName, const char* etlFileName);
ULONG __stdcall WriteEtw(const char* message);
ULONG __stdcall StopEtw();
ULONG __stdcall DecodeEtw(const char* loggerName, const char* etlFileName, const char* txtFileName);

JNIEXPORT jint JNICALL Java_microsoft_tracing_Loglib_initializeEtw (JNIEnv *env, jclass, jstring JloggerName, jstring JetlFileName);
JNIEXPORT jint JNICALL Java_microsoft_tracing_Loglib_writeEtw (JNIEnv *env, jclass, jstring jmessage);
JNIEXPORT jint JNICALL Java_microsoft_tracing_Loglib_stopEtw (JNIEnv *env, jclass);
JNIEXPORT jint JNICALL Java_microsoft_tracing_Loglib_decodeEtw (JNIEnv *env, jclass, jstring JloggerName, jstring JetlFileName, jstring jtxtFileName);
}
// private EXTRNs

extern ULONG g_level;
extern ULONG g_flags;
extern TRACEHANDLE loggerh;
extern TRACEHANDLE registrationh;
extern BOOL enabled;
extern GENERIC_EVENT GenericEvent;
extern PEVENT_TRACE_LOGFILE EvmFile;
extern ULONG LogFileCount;

extern ULONG TotalBuffersRead;
extern ULONG TotalEventsLost;
extern ULONG TotalEventCount;
extern ULONG TimerResolution;

extern ULONGLONG StartTime;
extern ULONGLONG EndTime;
extern BOOL   fNoEndTime;
extern __int64 ElapseTime;
extern HANDLE hDecodedFile;
extern PEVENT_TRACE_PROPERTIES loggerdata;

__declspec (selectany) char EtlLoggerFileName[MAX_PATH];
__declspec (selectany) char TxtLoggerFileName[MAX_PATH];
__declspec (selectany) char LoggerName[MAX_PATH];
__declspec (selectany) ULONG loggerdata_len;


